<?php
echo "<br>","echo","可以多语句输出","<br>";
print "print只能单语句输出<br>";
echo "数据类型：String（字符串）, Integer（整型）, Float（浮点型）, Boolean（布尔型）, Array（数组）, Object（对象）, NULL（空值）。<br><br>";

$x = 10.365;
//输出数据类型、数据值
var_dump($x);
echo "<br>"; 
$x = 2.4e3;
var_dump($x);
echo "<br>"; 
$x = 8E-5;
var_dump($x);


echo "<br><br>";
// 区分大小写的常量名
define("GREETING","PHP constant value");
$greeting = '自己写个 greeting 变量';
echo GREETING;    // 输出 "欢迎访问 Runoob.com"
echo '<br>';
echo $greeting;   // 输出 "greeting"
echo '<br>';
// 不区分大小写的常量名
define("GREETING", "欢迎访问 Runoob.com", true);
echo greeting;  // 输出 "欢迎访问 Runoob.com"
echo '<br>';


$txt1="Hello world!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2; 
echo '<br>';
echo strlen("Hello world!"); 
echo '<br>';
echo strpos("Hello world!","world"), "<br>", "<br>"; 


//逻辑运算符
echo "x and y:  如果 x 和 y 都为 true，则返回 true". "<br>";
echo "x or y:   如果 x 和 y 至少有一个为 true，则返回 true". "<br>";
echo "x xor y:  如果 x 和 y 有且仅有一个为 true，则返回 true". "<br>";
echo "&& || !,与或非". "<br>";
$x = 1;
$y = 2;
var_dump($x < 10 and $y > 1);
echo "<br><br>";

//三目运算符
$test = '菜鸟教程';
// 普通写法
$username = isset($test) ? $test : 'nobody';
echo $username, '<br>';
// PHP 5.3+ 版本写法
$username = $test ?: 'nobody';
echo $username, '<br>', '<br>';
/*
 php7.0+ 
 $c = $a <=> $b;
 如果 $a > $b, $c 的值为 1
 如果 $a == $b, $c 的值为 0
 如果 $a < $b, $c 的值为-1
 * */

//流程控制
$t=date("H");
if ($t<"12")
{
    echo "Have a good day!";
}
else
{
    echo "Have a good night!";
}
echo '<br>';
$favcolor="red";
switch ($favcolor)
{
    case "red":
        echo "你喜欢的颜色是红色!";
        break;
    case "blue":
        echo "你喜欢的颜色是蓝色!";
        break;
    case "green":
        echo "你喜欢的颜色是绿色!";
        break;
    default:
        echo "你喜欢的颜色不是 红, 蓝, 或绿色!";
}
echo "<br><br>";

/*
 * while循环
 $i=1;
while($i<=5)
{
    echo "The number is " . $i . "<br>";
    $i++;
}

do
{
$i++;
echo "The number is " . $i . "<br>";
}
while ($i<=5);
?>
 */

//数组
$cars=array("Volvo","BMW","Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "<br>";
$arrayLen = count($cars);
echo "数组长度：", $arrayLen, '<br>';
for($x=0;$x<$arrayLen;$x++)
{
    echo $cars[$x];
    echo "<br>";
}
echo '<br>';
// map
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
$age['Peter']="36";
echo "Peter is " . $age['Peter'] . " years old.", '<br>';
foreach ($age as $x=>$x_value) {
    echo "key=", $x, ", value=", $x_value, '<br>';
}
echo '<br>';
$numbers=array(4,6,2,22,11);
echo "sort array(4,6,2,22,11)    result:";
sort($numbers);
for($x=0;$x<count($numbers);$x++){
    echo $numbers[$x],'   ';
}
echo '<br>';
rsort($numbers);
echo "rsort array(4,6,2,22,11)    result:";
for($x=0;$x<count($numbers);$x++){
    echo $numbers[$x],'   ';
}
echo '<br><br>';
//
/*
 * asort() - 对map,vale升序排列
 * ksort() - 对map,key升序排列
 * 同理，有arsort()，krsort()降序排列
 * */


/*
超级全局变量

$GLOBALS
$_SERVER
$_REQUEST
$_POST
$_GET
$_FILES
$_ENV
$_COOKIE
$_SESSION
 * */
echo "\$GLOBALS示例<br>";
function globalVale() {
    $GLOBALS["y"] = $GLOBALS["x"];
    $y = 100;
}
globalVale();
echo "GLOBAL VAlue y:", $GLOBALS["y"], "  \$y:", $y, "<br><br>";

echo "\$_SERVER示例<br>";
echo "PHP_SELF : ",$_SERVER['PHP_SELF'], "<br>";
echo "SERVER_NAME : ",$_SERVER['SERVER_NAME'], "<br>";
echo "HTTP_HOST : ",$_SERVER['HTTP_HOST'], "<br>";
echo "HTTP_REFERER : ",isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:"", "<br>";
echo "HTTP_USER_AGENT : ",$_SERVER['HTTP_USER_AGENT'], "<br>";
echo "SCRIPT_NAME : ",$_SERVER['SCRIPT_NAME'], "<br><br>";

//magicalValue
echo '这是第 " '  . __LINE__ . ' " 行' . '<br>';
echo '该文件位于 " '  . __FILE__ . ' " ' . '<br>';
echo '该文件位于 " '  . __DIR__ . ' " ' . '<br>';
class test {
    function _print() {
        echo '类名为：'  . __CLASS__ . "<br>";
        echo  '函数名为：' . __FUNCTION__  . '<br><br>';
    }
}
$t = new test();
$t->_print();
//http://www.runoob.com/php/php-magic-constant.html










?>